package org.layui.servlet;

import org.layui.dao.UserDao;
import org.layui.dao.impl.UserDaoImpl;
import org.layui.entity.User;
import org.layui.vo.ResultVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 删除用户
 */
@WebServlet("/api/user/del")
public class UserDeleteServlet extends BaseServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 获取当前页和每页显示的记录数
        int id = Integer.parseInt(req.getParameter("id"));

        // 创建DAO对象，实现数据的查询（多条件+分页）
        UserDao userDao = new UserDaoImpl();
        int r = userDao.delete(id) ;
        if(r==1) {
            // 把分页的信息，封装到PageVO对象中，并返回到客户端
            print(resp, successJson("删除成功"));
            return ;
        }
        print(resp, errorJson("删除失败"));

    }
}
